<template>
	<!-- 选择时间 -->
	<picker mode="date" fields="month" :value="value" :start="startData" :end="endData" @change="bindDateChange">
		<view class="picker">
			<slot></slot>
		</view>
	</picker>
	<!-- 	
	<u-datetime-picker :visibleItemCount='8' ref="datetimePicker" @confirm="fnConfirm($event)" :minDate="minDate" :maxDate="maxDate" @cancel="fnCloseTimePicker"
		:formatter="formatter" :show="show" v-model="value1" :mode="mode">
		
	</u-datetime-picker> -->
</template>

<script>
	export default {
		props: {
			defaultValue: {
				default: '',
				type: String
			},
			start: {
				default: '',
				type: String
			},
			end: {
				default: '',
				type: String
			},
			valueData: {
				default: '',
				type: String
			}
		},
		data() {
			return {
				value: '',
				startData: '2024-04-01',
				endData: ''
			}
		},
		mounted() {
			
			// if (Number(new Date()) < Number(new Date('2024-05-01'))) {
			// 	this.startData = '2024-03-01';
			// }
			this.endData = this.getCurrentDate();
			
			if(this.start){
				this.startData = this.start
			}
			if(this.end){
				this.endData = this.end
			}
		},
		computed: {
			filterDateText() {
				if (this.valueData) {
					let ar = this.valueData.split("-");
					if (ar.length > 0) {
						return ar[0] + '年' + Number(ar[1]) + '月';
					}
					return "";
				}
				return ""
			},
		},
		methods: {
			getCurrentDate() {
				let y = new Date().getFullYear()
				let m = new Date().getMonth() + 1
				m = m < 10 ? "0" + m : m
				return `${y}-${m}-01`
			},
			bindDateChange(e) {
				this.$emit('update:valueData', e.detail.value)
				this.$emit('dateChange')
			}
		}
	}
</script>
